<?php defined('BASEPATH') OR exit('No direct script access allowed');
@ini_set('memory_limit', '2048M');

$CI = new CI_Module();
$CI->load->model('line.Line_go_price_model');
$_table = $CI->db->dbprefix("line");

$OFFSET   = 0;
$PAGESIZE = 5000;
$path = 'price.log';

file_put_contents($path, PHP_EOL. 'START AT '.date('Y-m-d H:i:s').PHP_EOL, FILE_APPEND);
$lines = array();
do
{
    $lines = array();
    $query = $CI->db->query('SELECT line_id FROM '.$_table." where is_del=0 and status=1 AND conn_line_id=0 ORDER BY line_id DESC LIMIT $OFFSET, $PAGESIZE");
    $lines = $query->result_array();
    $query->free_result();
    if($lines){
        foreach ($lines as $line) {
            $CI->Line_go_price_model->trigger(array(), $line['line_id']);
        }
    }
    file_put_contents($path, $OFFSET. ' - '. (memory_get_usage()/1024/1024).PHP_EOL, FILE_APPEND);
    $OFFSET += $PAGESIZE;
}while($lines);
file_put_contents($path, $OFFSET. ' - END AT '.date('Y-m-d H:i:s').PHP_EOL, FILE_APPEND);